import request from '@/utils/request';
import type { ItemInfo } from './item';
import type { WarehouseInfo } from './warehouse';
// 假设用户信息的类型定义在 user.ts 中
// import type { UserInfo } from './user';

// 简单的 UserInfo 结构，如果 user.ts 存在请使用实际的定义
interface UserInfo {
    userId: number;
    username: string;
    realName?: string;
}

// 入库记录信息
export interface InboundRecordInfo {
  inboundId: number;
  itemId: number;
  item: ItemInfo; // 关联的物品信息
  warehouseId: number;
  warehouse: WarehouseInfo; // 关联的仓库信息
  quantity: number;
  unitPrice: number;
  totalAmount: number;
  supplier: string;
  operatorId: number;
  operator: UserInfo; // 关联的操作员信息
  inboundTime: string; // 入库时间
  notes: string;
  createdAt: string;
}

// 查询参数
export interface InboundRecordListParams {
  page?: number;
  pageSize?: number;
  itemId?: number; 
  warehouseId?: number; 
  startTime?: string;
  endTime?: string;
}

// 返回结构
export interface InboundRecordListResponse {
  list: InboundRecordInfo[];
  total: number;
  page: number;
  pageSize: number;
}

// 创建入库记录参数
export interface CreateInboundRecordParams {
  itemId: number;
  warehouseId: number;
  quantity: number;
  unitPrice: number;
  supplier: string;
  notes?: string;
}

// 创建入库记录返回
export interface CreateInboundRecordResponse {
    inboundId: number;
    itemId: number;
    warehouseId: number;
    quantity: number;
    unitPrice: number;
    totalAmount: number;
    supplier: string;
    operatorId: number;
    inboundTime: string; // 入库时间
    notes?: string;
    createdAt: string;
}

const inboundApi = {
  // 获取入库记录列表
  getInboundRecordList(params: InboundRecordListParams) {
    return request.get<InboundRecordListResponse>('/getInboundRecords', { params });
  },
  // 获取单个入库记录
  getInboundRecordById(id: number) {
    return request.get<InboundRecordInfo>(`/InboundRecordsById/${id}`);
  },
  // 创建入库记录
  createInboundRecord(data: CreateInboundRecordParams) {
    return request.post<CreateInboundRecordResponse>('/createInboundRecord', data);
  }
};

export default inboundApi; 